import { ContentTypeEnum } from '@/enums/httpEnum';
import { defHttp } from '@/utils/http/axios';
import {
  MenuListGetResultModel,
  MenuParams,
  CreateMenuParams,
  UpdateMenuParams,
} from './model/systemModel';

enum Api {
  Menu = '/menu/',
  SelectMenu = '/menu/select/tree',
  MenuList = '/menu/list',
  MenuNavList = '/menu/nav/list',
}

/**
 * 创建菜单
 * @param params CreateMenuParams
 * @returns Promise
 */
export const addMenu = (params?: CreateMenuParams) => defHttp.post({ url: Api.Menu, params });

/**
 * 更新菜单
 * @param params UpdateMenuParams
 * @returns Promise
 */
export const updateMenu = (params?: UpdateMenuParams) =>
  defHttp.post({ url: `${Api.Menu}${params?.id}`, params }, { isTransformResponse: false });

/**
 * 菜单列表
 * @param params
 * @returns
 */
export const getMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params });

/**
 * 批量删除菜单
 * @param ids 单个或多个菜单id，多个id之间用英文逗号分割
 * @returns Promise
 */
export const deleteMenuByIds = (ids: string) =>
  defHttp.delete(
    {
      url: `${Api.Menu}${ids}`,
      headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
      params: { ids },
    },
    { isTransformResponse: false },
  );

/**
 * 选择菜单
 * @returns Promise
 */
export const getSelectMenu = () => defHttp.get<MenuListGetResultModel>({ url: Api.SelectMenu });

export const getMenuNavList = () => defHttp.get<MenuListGetResultModel>({ url: Api.MenuNavList });
